package com.group3.merchant.utils;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.selector.ParseException;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.group3.entity.AMerchant;
import com.group3.entity.Merchant;

public class JMSUtil {
	
	public static void send(String string) throws JsonProcessingException,
			JMSException, ParseException {
		// 生产信息

		// 获取connectionFactory工厂，通过其实现类ActiveMQConnectionFactory
		ConnectionFactory cf = new ActiveMQConnectionFactory(
				"failover://tcp://10.222.29.166:61616");
		System.out.println(cf);

		// 获取
		Connection conn = cf.createConnection();
		System.out.println("conn:"+conn);
		Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		System.out.println("session:"+session);
		Destination queue = new ActiveMQQueue("Admin-Merchant53");
		System.out.println("queue:"+queue);
		MessageProducer producer = session.createProducer(queue);
		System.out.println("producer:"+producer);
		// 连接开始
		conn.start();

		TextMessage tm = session.createTextMessage(string);

		producer.send(tm);
//		session.commit();

		session.close();
		producer.close();
		conn.close();
	}

	public static AMerchant getStatus() throws JMSException {
		return null;
	}
}
